package own.stu.inter.loadbalance.server;

public class ServerInstance {

    private volatile String id;
    private String host;
    private int port = 80;
    private volatile boolean isAliveFlag;
    private volatile boolean readyToServe = true;// TODO del

    public ServerInstance(String host, int port) {
        this.host = host;
        this.port = port;
        this.id = host + ":" + port;
        isAliveFlag = false;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public boolean isAlive() {
        return isAliveFlag;
    }

    public void setAlive(boolean isAliveFlag) {
        this.isAliveFlag = isAliveFlag;
    }

    public void setAliveFlag(boolean aliveFlag) {
        isAliveFlag = aliveFlag;
    }

    public final boolean isReadyToServe() {
        return readyToServe;
    }

    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (null == this.getId() ? 0 : this.getId().hashCode());
        return hash;
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!(obj instanceof ServerInstance))
            return false;
        ServerInstance svc = (ServerInstance) obj;
        return svc.getId().equals(this.getId());
    }

    public String toString() {
        return this.getId();
    }
}
